l1,r1,l2,r2,k=map(int,input().split())
l=max(l1,l2)
r=min(r1,r2)
if (l>r):
print(0)
else:
if (k>=l and k<=r):
print(r-l)
else:
print(r-l+1)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll MAXN = 2e5+100;
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define fork(i,a,n) for(ll i=a; i<n; i++)
#define kfor(i,a,n) for(ll i=a; i>=n; i--)
#define input(v,n) for(ll i=0; i<n; i++) cin>>v[i];
#define max(x) *max_element(all(x))
#define min(x) *min_element(all(x))
#define sum(x) accumulate(all(x), 0LL)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
void ok(bool foo){foo?yes:no;}
//cout << fixed << setprecision(n) << << endl;
int main(){
io
ll l1, r1, l2, r2, k, c1, c2, c=0;
cin >> l1 >> r1 >> l2 >> r2 >> k;
if(l1 <= l2){
if(r1 >= r2) {
if(k >= l2 and k <= r2) {
c = r2 - l2;
}
else {
c = r2 - l2 + 1;
}
}
else if(r1 < l2) {
}
else if(k <= r1 and k >= l2) {
c = r1 - l2;
}
else {
c = r1 - l2 + 1;
}
}
else {
if(r2 >= r1) {
if(k >= l1 and k <= r1) {
c = r1 - l1;
}
else {
c = r1 - l1 + 1;
}
}
else if(r2 < l1) {
}
else if(k <= r2 and k >= l1) {
c = r2 - l1;
}
else {
c = r2 - l1 + 1;
}
}
cout << c << endl;
return 0;
}
1725G - Garage | 1725B - Basketball Together |
735A - Ostap and Grasshopper | 1183B - Equalize Prices |
1481A - Space Navigation | 1437B - Reverse Binary Strings |
1362B - Johnny and His Hobbies | 1299A - Anu Has a Function |
1111A - Superhero Transformation | 954A - Diagonal Walking |
39F - Pacifist frogs | 1451C - String Equality |
386A - Second-Price Auction | 1690E - Price Maximization |
282B - Painting Eggs | 440A - Forgotten Episode |
233B - Non-square Equation | 628B - New Skateboard |
262B - Roma and Changing Signs | 755C - PolandBall and Forest |
456B - Fedya and Maths | 376B - IOU |
1623B - Game on Ranges | 1118A - Water Buying |
1462C - Unique Number | 301A - Yaroslav and Sequence |
38A - Army | 38C - Blinds |
1197A - DIY Wooden Ladder | 1717D - Madoka and The Corruption Scheme |